package com.example.firstopengl.objects;

import android.opengl.GLES20;

import com.example.firstopengl.data.VertexArray;
import com.example.firstopengl.programs.ColorShaderProgram;

import static com.example.firstopengl.util.Constant.BYTES_PER_FLOAT;

/**
 * Created by liqian-ps on 2017/7/6.
 */

public class Mallet {
    private static final int POSITION_COMPONENT_COUNT = 2;
    private static final int COLOR_COMPONENT_COUNT = 3;
    private static final int STRIDE = (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) * BYTES_PER_FLOAT;


    private float[] VERTEX_DATA = {
      // x, y  , r, g ,b
            0f, 0.4f, 1.0f, 0.0f, 0f,
            0f, -0.4f, 0f, 0f, 1.0f
    };

    private VertexArray vertexArray;
    public Mallet(){
        vertexArray = new VertexArray(VERTEX_DATA);
    }

    public void bindData(ColorShaderProgram colorProgram){
        vertexArray.setVertexAttribPointer(0, colorProgram.getPositionLocation(), POSITION_COMPONENT_COUNT, STRIDE);
        vertexArray.setVertexAttribPointer(POSITION_COMPONENT_COUNT, colorProgram.getColorLocation() , COLOR_COMPONENT_COUNT, STRIDE);
    }

    public void draw(){
        GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 2);
    }
}
